package com.example.tool.action.util;

import com.example.tool.action.ActionUtil;
import com.example.tool.utils.FileUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Title: OtherUtilActions</p>
 * Description: 创建其他工具类
 * <p>CreateTime: 2022/6/27 18:10</p>
 *
 * @author FT
 */
public class OtherUtilActions extends AnAction {

    @Override
    public @NotNull ActionUpdateThread getActionUpdateThread() {
        return super.getActionUpdateThread();
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        ActionUtil.ActionCreatInput(e, (information, value) -> {
            String className = value.get(0);
            // xx.java
            FileUtil.generateFile(information[0] + "/" + className + ".java", "/demo/init/utils/OtherUtil.txt",
                    str -> str.replace("$package$", information[1])
                            .replace("$ClassName$", className)
                            .replace("$TIME$", new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
            VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
        }, "其他工具类名: ");
    }

    @Override
    public void update(@NotNull AnActionEvent event) {
        ActionUtil.ActionP(event);
    }
}
